package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bwie.mapper.SkuMapper;
import com.bwie.mapper.StockMapper;
import com.bwie.pojo.Sku;
import com.bwie.pojo.Stock;
import com.bwie.service.SkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program: day0423-pxx
 * @ClassName SkuServiceImpl
 * @description:
 * @author: 段阳
 * @create: 2024-05-06 11:47
 **/
@Service
@Transactional
public class SkuServiceImpl implements SkuService {

    @Autowired
    private SkuMapper skuMapper;

    @Autowired
    private StockMapper stockMapper;


    @Override
    public List<Sku> findSkuList(Long id) {
        List<Sku> list = skuMapper.selectList(new QueryWrapper<Sku>().lambda().eq(Sku::getSpuId, id));
        for (Sku sku : list) {
            Stock stock = stockMapper.selectById(sku.getId());
            sku.setStock(stock.getStock());
        }
        return list;
    }
}